#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int N, T;
constexpr int  MAXN = 1000002;
int record[MAXN];

void solve();
int main() {
   
    int start, over;
    while (scanf("%d%d", &N, &T) != EOF) {
        memset(record, 0, sizeof record);
        while (N--) {
            scanf("%d%d", &start, &over);
            record[start] = max(record[start], over);
        }
        solve();
    }
    return 0;
    
}

void solve() {
    int s = 0, now = 0, res = 0;
    while (true) {
        int target = 0;
        if (s >= T) {
            printf("%d\n", res);
            return;
        }
        for (int i = now; i < s + 2; i++)
            target = max(target, record[i]);
            
        if (target <= s) {
            printf("-1\n");
            return;
        }
        res += 1;
        now = s; s = target;
    }
}